const express = require("express");
const http = require("http");
const serveIndex = require("serve-index");//发布目录
const path = require("path");
const bodyParser = require("body-parser");


const serverRoute = require('./src/router/serverStatus')

const app = express();
app.use(bodyParser.json({ limit: "20mb" })); // for parsing application/json



//设置允许跨域访问该服务.
app.all("*", function (req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  //Access-Control-Allow-Headers ,可根据浏览器的F12查看,把对应的粘贴在这里就行
  res.header("Access-Control-Allow-Headers", "Content-Type");
  res.header("Access-Control-Allow-Methods", "*");
  //res.header('Content-Type', 'application/json;charset=utf-8');
  next();
});

// const staticPath = path.resolve(__dirname + "/pubilc");
// app.use(serveIndex(staticPath));
// app.use(express.static(staticPath));

//解析URL-encoded格式的请求体数据
app.use(express.urlencoded());
//解析JSON格式的请求体数据
app.use(express.json());

//信令服务状态
app.use('/serverStatus',serverRoute)

//http
const socketStart = require("./src/index");
const http_serve = http.createServer(app);
socketStart(http_serve);
http_serve.listen(8088, "0.0.0.0", () => {
  console.log("listening on 8088");
});
